f = open("E:\excel学习文档-表格\黑马-可视化案例数据\地图-疫情.txt",'r',encoding = "UTF-8")
data = f.read()
f.close()
import json
data_dict = json.loads(data)
# 提取每个市区的数据
henan_data = data_dict['areaTree'][0]['children'][3]
cities_data = henan_data['children']

# 组装每个市区和确诊人数为元组，并将各个市区的数据封装为列表
data_list = []
for city_data in cities_data:
    city_name = city_data['name']+"市"
    # print(city_data)
    city_confirm = city_data['total']['confirm']
    # print(city_confirm)
    data_list.append((city_name,city_confirm))
# print(data_list)
# print(type(data))
# 手动添加济源市的确诊数据
data_list.append(("济源市",5))
print(data_list)

# 画图
from pyecharts.charts import Map
from pyecharts.options import TitleOpts,VisualMapOpts,TitleOpts

map = Map()
map.add("河南省各市区确诊人数",data_list,"河南")
map.set_global_opts(
    title_opts = TitleOpts("河南省疫情地图",pos_left = "center",pos_bottom = "1%"),
    visualmap_opts = VisualMapOpts(
        is_show = True,
        is_piecewise = True,
        pieces =(
            {"min":1,"max":50,"label":"1-50人","color":"#00FF33"},
            {"min":51,"max":100,"label":"51-100人","color":"#66FFFF"},
            {"min":101,"max":250,"label":"101-250人","color":"#FF99FF"},
            {"min":251,"label":">250人","color":"#9933FF"},
        )
    )
)
map.render("河南省疫情地图.html")